package me.send.produce.client.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.send.business.base.Page;
import me.send.business.service.bean.ReturnBean;
import me.send.business.service.bean.ReturnJsonBean;
import me.send.business.service.pojo.BrokerInfoBean;
import me.send.business.service.service.BrokerEvaluateService;
import me.send.business.service.service.PopuserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "popuser")
public class PopuserController {

	@Autowired
	private PopuserService popuserService;
	@Autowired
	BrokerEvaluateService brokerEvaluateService;

	@RequestMapping(value = "page/userid")
	@ResponseBody
	public Map<String, Object> page_userid(Page page, Integer userid,
			String devicenumber) {
		return popuserService.page_userid(page, userid, devicenumber);
	}

	/**
	 * 用户收藏经纪人
	 * 
	 * @param userid
	 * @param brokerid
	 * @return
	 */
	@RequestMapping("/collection")
	@ResponseBody
	public ReturnJsonBean collectionBroker(int userid, int brokerid,String devicenumber) {
		ReturnJsonBean returnBean = new ReturnJsonBean();
		int colletAction = popuserService.collectionBroker(userid, brokerid);
		if (colletAction > 0) {
			returnBean.setCode(ReturnBean.SUCCESS);
			returnBean.setMessage(ReturnBean.SUCCESS_STR);
			returnBean.setDatas(colletAction);
		}
		return returnBean;
	}

	/**
	 * 获取经纪人信息
	 * 
	 * @param brokerid
	 * @param devicenumber
	 * @return
	 * @author maxmin
	 * @date 2015年8月25日下午4:23:33
	 */
	@RequestMapping(value = "detial")
	@ResponseBody
	public ReturnJsonBean brokerDetial(int brokerid, int userid,String devicenumber) {
		ReturnJsonBean rb = new ReturnJsonBean();
		try {
			BrokerInfoBean broker = popuserService.getBrokerInfo(brokerid,userid);
			List<Map<String, Object>> evaluates = brokerEvaluateService
					.getEvaluates(brokerid);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("broker", broker);
			map.put("evaluates", evaluates);
			rb.setDatas(map);
			rb.setCode(ReturnJsonBean.SUCCESS);
			rb.setMessage(ReturnJsonBean.SUCCESS_STR);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rb;
	}
	
	/**
	 * 
	 * @param userid
	 * @param devicenumber
	 * @return
	 * @author maxmin
	 * @date 2015年9月2日上午9:23:10
	 */
	@RequestMapping(value="collecbrokerlist")
	@ResponseBody
	public ReturnJsonBean collectionBrokerList(int userid,String devicenumber,int startid,int size){
		ReturnJsonBean rb = new ReturnJsonBean();
		try {
			rb.setDatas(popuserService.collectionBrokerList(userid, startid, size));
			rb.setCode(ReturnJsonBean.SUCCESS);
			rb.setMessage(ReturnJsonBean.SUCCESS_STR);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rb;
	}
}
